﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
namespace DAO
{
    public class NguyenVatLieuDAO : DataProvider
    {
        public ArrayList GetNguyenVatLieu()
        {
            connect();
            string sql = "select * from NguyenVatLieu";
            adapter = new SqlDataAdapter(sql, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);
            disconnect();
            return arr;
        }
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            NguyenVatLieuDTO dto = new NguyenVatLieuDTO(); 
            try{ 
                dto.NGUYEN_VAT_LIEU_ID = int.Parse(dt.Rows[i][0].ToString()); 
                dto.TEN_NGUYEN_VAT_LIEU = dt.Rows[i][1].ToString();
                dto.DON_VI_TINH = dt.Rows[i][3].ToString(); 
                dto.SO_LUONG_TON = int.Parse(dt.Rows[i][4].ToString()); 
            } 
            catch { }
            return (object)dto;
        }

        public string GetTenNVL(int p)
        {
            connect();
            string tennvl = null;
            string sql = "select ten_nvl from NguyenVatLieu where nvl_id=" + p;
            SqlCommand cmd = new SqlCommand(sql, connection);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                tennvl = reader.GetString(0);
            }
            disconnect();
            return tennvl;
        }
    }
}
